<?php

namespace app\api\controller;

use think\Queue;

class Game extends Api
{
    public function dismiss()
    {
        //获取参数
        $data = file_get_contents("php://input");
        if (empty($data)) {
            $this->error("post is null");
        }
        $params = json_decode($data, true);

        /*创建新消息并推送到消息队列*/
        // 当前任务由哪个类负责处理
        $job_handler_classname = "app\api\job\Dismiss";
        // 当前队列归属的队列名称
        $job_queue_name = "dismiss_job_queue";
        // 当前任务所需的业务数据
        $job_data = ["ts" => time(), "bizid" => uniqid(), "params" => $params];
        // 将任务推送到消息队列等待对应的消费者去执行
        $is_pushed = Queue::push($job_handler_classname, $job_data, $job_queue_name);
        if ($is_pushed == false) {
            $this->error("dismiss job queue went wrong");
        }
        //操作成功
        $this->success('success');
    }
}